package com.delivery.www.service.ServiceImpl;

import com.delivery.www.dao.DishDao;
import com.delivery.www.po.Collect;
import com.delivery.www.po.Dish;
import com.delivery.www.po.Thumb;
import com.delivery.www.service.DishService;
import com.delivery.www.constant.Constants;
import com.delivery.www.dao.DaoImpl.DishDaoImpl;

import java.util.List;

/**
 * @author 12970
 */
public class DishServiceImpl implements DishService {
    private final DishDao dishDao = new DishDaoImpl();

    @Override
    public List<Dish> getDish(int storeId, String dishName, int currentPageNo, int pageSize) {
        if (storeId <= 0 || currentPageNo <= 0 || pageSize <= 0) {
            return null;
        } else {
            return dishDao.getDish(storeId, dishName, currentPageNo, pageSize);
        }
    }

    @Override
    public int addDish(String dishName, int storeId, Float price, String describe) {
        if (dishName == null || storeId <= 0 || price < 0 || describe == null) {
            return 0;
        } else {
            return dishDao.addDish(dishName, storeId, price, describe);
        }
    }

    @Override
    public boolean updateDishName(int dishId, String newName, int storeId) {
        if (dishId <= 0 || newName == null || storeId <= 0) {
            return false;
        } else {
            return dishDao.updateDishName(dishId, newName, storeId) > 0;
        }
    }

    @Override
    public boolean updateDishPrice(int dishId, Float price, int storeId) {
        if (dishId <= 0 || price < 0 || storeId <= 0) {
            return false;
        } else {
            return dishDao.updateDishPrice(dishId, price, storeId) > 0;
        }
    }

    @Override
    public boolean updateDishDescribe(int dishId, String introduce, int storeId) {
        if (dishId <= 0 || introduce == null || storeId <= 0) {
            return false;
        } else {
            return dishDao.updateDishDescribe(dishId, introduce, storeId) > 0;
        }
    }

    @Override
    public boolean deleteDish(int dishId, int storeId) {
        if (dishId <= 0 || storeId <= 0) {
            return false;
        } else {
            return dishDao.deleteDish(dishId, storeId) > 0;
        }
    }

    @Override
    public Dish getOneDish(int dishId) {
        if (dishId <= 0) {
            return null;
        } else {
            return dishDao.getOneDish(dishId);
        }
    }

    @Override
    public List<Dish> getThumbDish(List<Thumb> thumbs) {
        return dishDao.getThumbDish(thumbs);
    }

    @Override
    public List<Dish> getCollectDish(List<Collect> collects) {
        return dishDao.getCollectDish(collects);
    }

    @Override
    public int getDishCount(int storeId, String dishName) {
        if (storeId <= 0) {
            return 0;
        } else {
            return dishDao.getDishCount(storeId, dishName);
        }
    }

    @Override
    public List<Dish> getDish(int storeId) {
        if (storeId <= 0) {
            return null;
        } else {
            return dishDao.getDish(storeId);
        }
    }

    @Override
    public boolean judgeField(int dishId, String value, int storeId, String field) {
        boolean b;
        if (field.equals(Constants.DESCRIBE)) {
            b = updateDishDescribe(dishId, value, storeId);
        } else if (field.equals(Constants.DISH_NAME)) {
            b = updateDishName(dishId, value, storeId);
        } else {
            b = updateDishPrice(dishId, Float.parseFloat(value), storeId);
        }
        return b;
    }
}
